package com.wgj.android.ui.activity;

import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.jiaai.xui.XUI;
import com.jiaai.xui.utils.XEmptyUtils;
import com.wgj.android.R;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/11/20.
 */

public class QuestionActivity extends AppCompatActivity  {
    private static Map<String,String> questions=new HashMap<>();
    private  static Map<String,String> answers=new HashMap<>();

    private int answersIndex=0;
    private  String questionIndex="";
    private AnimationSet animatorSet;
    @BindView(R.id.question)
    TextView questionTextView;

    @BindView(R.id.questionView)
    View questionView;

    @BindView(R.id.answer)
    TextView answerTextView;



    static {
        questions.put("1","以前生过孩子没有?");
        questions.put("1_1","最近一胎是男孩还是女孩?");
        questions.put("1_2","双方身体是否健康，具备生孩子的条件?");

        questions.put("1_1_1","小孩准确年龄?");



        questions.put("2_1","想要男孩还是女孩?");

        questions.put("2_1_1","男方准确阴历出生年龄（精确到时辰）");
        questions.put("2_1_2","女方准确阴历出生年龄（精确到时辰）");


        questions.put("3_1","女方每月例假是否准时?");

        questions.put("3_1_1","每月几号（阴历）?");
        questions.put("3_1_2","是提前还是推迟?");

        questions.put("3_1_2_1","一般提前几天?");
        questions.put("3_1_2_2","一般推迟几天?");

        questions.put("4_1","最近一次例假开始时间?");
        questions.put("4_2","最近一次例假结束时间?");

    }



    @SuppressLint("ResourceType")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.question_activity);
        ButterKnife.bind(this);
        animatorSet= (AnimationSet) AnimationUtils.loadAnimation(this,R.anim.question_anim);
        animatorSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                generateQuestion();
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        questionView.startAnimation(animatorSet);

    }


    private  void generateQuestion(){


        questionTextView.setText(questions.get(questionIndex));
        answerTextView.setText("");
    }

    private void bindEevnt(){
        switch (questionIndex){
            case "1":
                answerTextView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
                break;
        }
    }


    private String  generateIndex(){
        String nextQuestionIndex=questionIndex+"_"+answersIndex;
        if(questions.containsKey(nextQuestionIndex)){
            return nextQuestionIndex;
        }else {
        return "";
        }
    }

    private  void  showSingleAlertDialog(String title,String[] items,int check){
        AlertDialog dialog = new AlertDialog.Builder(this).setTitle(title)
                .setSingleChoiceItems(items, check, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        questionView.startAnimation(animatorSet);
                        dialog.dismiss();
                    }
                }).create();
        dialog.show();
    }
}
